<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
//账户设置
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'base';
$return=array();
if($_RQ['op']=='base'){
	$return['item']=pdo_get('core_account_wxapp_info',array('uniacid'=>$_SESSION['uniacid']),array('title','logo','desc','hdps','anlis','biaoqian','default_wxapp'));
	$site=pdo_get('core_accounts',array('uniacid'=>$_SESSION['uniacid']),array('title','logo','desc'));
	if(empty($return['item'])){
		$data=array(
			'uniacid'=>$_SESSION['uniacid'],
			'title'=>$site['title'].'小程序',
			'logo'=>$site['logo'],
			'desc'=>$site['desc'],
			'biaoqian'=>'[{"title":"餐饮","icon":"fa-cutlery","desc":"智慧点餐，外卖，店内点餐！"},{"title":"商城","icon":"fa-shopping-cart","desc":"无人超市，小卖铺，生鲜配送！"},{"title":"城市","icon":"fa-building-o","desc":"多商户，代理，发布二手信息，手机开店"},{"title":"教育","icon":"fa-graduation-cap","desc":"课堂，在线作业，幼儿培训"},{"title":"预约","icon":"fa-pencil-square-o","desc":"预约服务，美业，上门预约"},{"title":"服务","icon":"fa fa-coffee","desc":"比如优剪，上门服务，手机维修！"},{"title":"社交","icon":"fa-heart","desc":"交友，互动，周游等"},{"title":"直播","icon":"fa-file-video-o","desc":"直播在线，迷你视频"},{"title":"配送","icon":"fa-truck","desc":"生鲜配送，人人跑腿"},{"title":"游戏","icon":"fa-google-plus","desc":"互动游戏，活动营销"},{"title":"车服","icon":"fa-automobile","desc":"微信挪车，拼车客"}]',
			'hdps'=>'[{"picurl":"../core/resource/images/banner-1.jpg"},{"picurl":"../core/resource/images/banner-2.jpg"}]',
			'anlis'=>'[{"biaoqian":"10","title":"车主秘书","picurl":"http://demo.jinyunweb.com/resource/images/2018/05/Crb9wZtlbg.jpg","ewm":"http://demo.jinyunweb.com/resource/images/2018/05/P7dBO3CkF1.jpg"},{"title":"实习僧-高薪版","biaoqian":"5","picurl":"http://demo.jinyunweb.com/resource/images/2018/05/FhMyvgRTEE.jpg","ewm":"http://demo.jinyunweb.com/resource/images/2018/05/3KiWSmkqrA.jpg"},{"picurl":"http://demo.jinyunweb.com/resource/images/2018/05/vJ5CcoIOwz.jpg","ewm":"http://demo.jinyunweb.com/resource/images/2018/05/sIcWHiUyJs.jpg","title":"连咖啡","biaoqian":"0"},{"title":"菜谱儿","picurl":"http://demo.jinyunweb.com/resource/images/2018/05/c1cRCEnFSC.jpg","ewm":"http://demo.jinyunweb.com/resource/images/2018/05/RZUxpIwIvo.jpg","biaoqian":"0"},{"title":"大学有答案","picurl":"http://demo.jinyunweb.com/resource/images/2018/05/ygWdec9fPZ.png","ewm":"http://demo.jinyunweb.com/resource/images/2018/05/Pc2oOEcVGv.jpg","biaoqian":"3"},{"picurl":"http://demo.jinyunweb.com/resource/images/2018/05/trYzk2jo2f.jpg","ewm":"http://demo.jinyunweb.com/resource/images/2018/05/KOdmA5slXJ.jpg","title":"汇聚乐","biaoqian":"6"},{"title":"享物说","picurl":"http://demo.jinyunweb.com/resource/images/2018/05/CB9AOcInUy.jpg","ewm":"http://demo.jinyunweb.com/resource/images/2018/05/Wg4kdViu3n.png","biaoqian":"1"},{"title":"看折扣","picurl":"http://demo.jinyunweb.com/resource/images/2018/05/DwD5UvNhxY.jpg","ewm":"http://demo.jinyunweb.com/resource/images/2018/05/Wn2Nzi7C3O.png","biaoqian":"1"},{"title":"化州生活网","picurl":"http://demo.jinyunweb.com/resource/images/2018/05/RrF7EgrWo2.png","ewm":"http://demo.jinyunweb.com/resource/images/2018/05/7oVLjBnMmu.jpg","biaoqian":"2"},{"title":"君秘群助","picurl":"http://demo.jinyunweb.com/resource/images/2018/05/fJpPCamTRx.png","ewm":"http://demo.jinyunweb.com/resource/images/2018/05/dyLds01fLX.jpg","biaoqian":"6"},{"title":"猫脉","picurl":"http://demo.jinyunweb.com/resource/images/2018/05/29OHnGKj3v.png","ewm":"http://demo.jinyunweb.com/resource/images/2018/05/flhaotOYTL.jpg","biaoqian":"6"},{"title":"G纵队","picurl":"http://demo.jinyunweb.com/resource/images/2018/05/qVUNgUWYlB.png","ewm":"http://demo.jinyunweb.com/resource/images/2018/05/ATvWHDqZyu.jpg","biaoqian":"6"},{"title":"容易拼","picurl":"http://demo.jinyunweb.com/resource/images/2018/06/YNue36F92B.png","ewm":"http://demo.jinyunweb.com/resource/images/2018/06/IEm5A6pUPm.jpg","biaoqian":"1"},{"title":"答题星","picurl":"http://demo.jinyunweb.com/resource/images/2018/06/DLc3Z5w7Ew.jpg","ewm":"http://demo.jinyunweb.com/resource/images/2018/06/r7q6YWJJoz.jpg","biaoqian":"3"},{"title":"一起猜数字","picurl":"http://demo.jinyunweb.com/resource/images/2018/06/UQmeEM844g.jpg","ewm":"http://demo.jinyunweb.com/resource/images/2018/06/vB7bOIdnKb.jpg"},{"title":"加减大师挑战赢娃娃","picurl":"http://demo.jinyunweb.com/resource/images/2018/06/p9X3Lwk5Ih.png","ewm":"http://demo.jinyunweb.com/resource/images/2018/06/BL1YGuIBbp.jpg","biaoqian":"9"},{"title":"哪儿有厕所","picurl":"http://demo.jinyunweb.com/resource/images/2018/06/6PAB55ataA.jpg","ewm":"http://demo.jinyunweb.com/resource/images/2018/06/ylh6cdTYAR.jpg","biaoqian":"2"}]'
		);
		pdo_insert('core_account_wxapp_info',$data);
		exi('添加演示数据成功！','','base');
	}
	$return['item']['hdps']=json_decode($return['item']['hdps'],true);
	$return['item']['anlis']=json_decode($return['item']['anlis'],true);
	$return['item']['biaoqian']=json_decode($return['item']['biaoqian'],true);
	$return['biaoqian']=$return['item']['biaoqian'];
	$return['item']['curl']=custom_url('core/home.wxapp/',true);
	$return['wxapps']=pdo_getall('core_account_wxapp',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$htmls=array(
			'type'=>'edit',
			'post'=>'post',
			'desc'=>'微信小程序基本信息(方便生成小程序宣传页)',
			'tabs'=>array(
				'0'=>array('op'=>'base','title'=>'小程序设置'),
			),
			'edit'=>array(
				array('type'=>'ewm','name'=>'curl','title'=>'宣传入口二维码','help'=>'扫码进入的是手机端的，小程序端的需自行发布！'),
				array('type'=>'copy','title'=>'链接地址','name'=>'curl', 'help'=>'复制地址，打包成小程序发布' ),
				array('type'=>'select','title'=>'默认小程序','name'=>'default_wxapp', 'help'=>'指定默认小程序，用于全局展示，留空则抓取第一个小程序作为展示！','options'=>'wxapps'),
				array('type'=>'href','title'=>'上传小程序','url'=>'core/setting.wxapp/up_app/id='.$return['item']['default_wxapp'],'btntitle'=>'上传小程序', 'help'=>'本小程序是纯原生态官网类小程序，内置站点新闻，视频，商城等，可以很好的通过小程序形式展现在《今日头条》等APP平台'),
				array('type'=>'string','title'=>'小程序名称','name'=>'title', 'help'=>''),
				array('type'=>'string','title'=>'小程序描述','name'=>'desc', 'help'=>'' ),
				array('type'=>'image','title'=>'小程序图标','name'=>'logo', 'help'=>'' ),
				array(
					'type'=>'array',
					'name'=>'biaoqian',
					'add_tip'=>'添加一个分类',
						'list'=>array(
							array('type'=>'icon','name'=>'icon','title'=>'分类icon'),
							array('type'=>'string','name'=>'title','title'=>'分类名称'),
							array('type'=>'string','name'=>'desc','title'=>'分类描述'),
							
						),
						'details'=>array(
							array('type'=>'icon','name'=>'icon','title'=>'分类icon'),
							array('type'=>'string','name'=>'title','title'=>'分类名称'),
							array('type'=>'string','name'=>'desc','title'=>'分类描述'),
							
						)
				),
				array(
					'type'=>'array',
					'name'=>'hdps',
					'add_tip'=>'添加一个幻灯片',
						'list'=>array(
							array('type'=>'image','name'=>'picurl','title'=>'幻灯片图片'),
							array('type'=>'string','name'=>'url','title'=>'幻灯片链接'),
							
						),
						'details'=>array(
							array('type'=>'image','name'=>'picurl','title'=>'幻灯片图片','help'=>''),
							array('type'=>'string','name'=>'url','title'=>'幻灯片链接'),
							
						)
				),
				array(
					'type'=>'array',
					'name'=>'anlis',
					'add_tip'=>'添加一个案例',
						'list'=>array(
							array('type'=>'image','name'=>'picurl','title'=>'案例图片'),
							array('type'=>'image','name'=>'ewm','title'=>'小程序二维码'),
							array('type'=>'string','name'=>'title','title'=>'案例标题'),
						),
						'details'=>array(
							array('type'=>'image','name'=>'picurl','title'=>'案例图片','help'=>''),
							array('type'=>'image','name'=>'ewm','title'=>'二维码'),
							array('type'=>'string','name'=>'title','title'=>'案例标题'),
							array('type'=>'radio','title'=>'分类','name'=>'biaoqian', 'options'=>'biaoqian')
							
						)
				)
			)
		);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if($_SESSION['user']['type']<3 && !$_SESSION['isfounder']){
		exi('您没有权限设置！','error');
	}
	$data=array(
		'title'=>trim($postdata['title']),
		'logo'=>trim($postdata['logo']),
		'desc'=>trim($postdata['desc']),
		'biaoqian'=>ijson_encode($postdata['biaoqian']),
		'hdps'=>ijson_encode($postdata['hdps']),
		'anlis'=>ijson_encode($postdata['anlis']),
		'default_wxapp'=>intval($postdata['default_wxapp']),
	);
	pdo_update('core_account_wxapp_info',$data,array('uniacid'=>$_SESSION['uniacid']));
	exi('设置成功！');
}
if($_RQ['op']=='up_app'){
	//上传小程序
	$id=intval($_RQ['id']);
	if(!$id){
		$id=pdo_getcolumn('core_account_wxapp_info',array('uniacid'=>$_SESSION['uniacid']),'default_wxapp');
	}
	if(!$id){
		exi('请先选择默认小程序，并保存！','error','core/setting.wxapp/');
	}
	$pagespath='core/home/welcome/index';
	$return['htmls']=array(
			'type'=>'look',
			'desc'=>'上传小程序',
			'tabs'=>array(
				array('action'=>'core/setting.wxapp/version_list/id='.$id,'title'=>'小程序版本列表'),
			),
			'look'=>array(
				array('type'=>'tip','title'=>'<red>【温馨提示】：务必先设置好站点小程序，移步：站点设置--站点小程序；</red></br>除了微信小程序，其他小程序都需要下载小程序版本，手动上传！本小程序默认路径：<red>'.$pagespath.'</red> 用于微信官方：发布版本，体验版本路径的设置！</br>本小程序是纯原生态官网类小程序，内置站点新闻，视频，商城等，可以很好的通过小程序形式展现在《今日头条》等APP平台,起到品牌宣传的作用！'),
				array('type'=>'href','url'=>'core/setting.wxapp/add_version/apptype=wxapp&id='.$id,'title'=>'微信小程序','help'=>'','btntitle'=>'生成新版本'),
				array('type'=>'href','url'=>'core/setting.wxapp/add_version/apptype=ttapp&id='.$id,'title'=>'抖音/头条小程序','btntitle'=>'生成新版本','help'=>''),
				array('type'=>'href','url'=>'core/setting.wxapp/add_version/apptype=aliapp&id='.$id,'title'=>'支付宝小程序','btntitle'=>'生成新版本','help'=>''),
				array('type'=>'href','url'=>'core/setting.wxapp/add_version/apptype=baiduapp&id='.$id,'title'=>'百度小程序','btntitle'=>'生成新版本','help'=>''),
				array('type'=>'href','url'=>'core/setting.wxapp/add_version/apptype=qqapp&id='.$id,'title'=>'QQ小程序','btntitle'=>'生成新版本','help'=>''),
			),
	);
	exi($return);
}
if($_RQ['op']=='add_version'){
		//添加版本
		$app_id=intval($_RQ['id']);
		$item=pdo_get('core_account_wxapp',array('id'=>$app_id));
		if(!$item){
			exi('指定小程序不存在！','error');
		}
		$item['setting']=$item['setting']?json_decode($item['setting'],true):array();
		$params=array(
			'appid'=>$item['appid'],
			'tt_appid'=>$item['tt_appid'],
			'ali_appid'=>$item['ali_appid'],
			'baidu_appid'=>$item['baidu_appid'],
			'qq_appid'=>$item['qq_appid'],
			'type'=>2,
			'title'=>$item['title'],
			'logo'=>tomedia($item['logo']),
			'siteroot'=>get_account_url(),
			'uniacid'=>$_SESSION['uniacid'],
			'app_id'=>$item['id'],
			'att_url'=>ATTACHMENT_URL,
			'setting'=>ijson_encode($tpl['setting']),
			'url'=>$item['url'],
			'web_id'=>$item['web_id'],
			'isdiyindex'=>$item['isdiyindex'],
			'plugin_name'=>$item['plugin_name'],
			'istabbar'=>$item['istabbar'],
			'sharetitle'=>$item['sharetitle'],
			'sharedesc'=>$item['sharedesc'],
			'shareimg'=>tomedia($item['shareimg']),
		);
		$params['cloud_id']='jy_demo';
		$menu=pdo_getcolumn('core_diy_menu',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'plugin'=>'core'),'data');
		if($menu){
			$menu=json_decode($menu,true);
			$params['menu']=$menu;
		}
		$post=array('params'=>base64_encode(ijson_encode($params)),'apptype'=>$_RQ['apptype']);
		$res=cloud_request('wxapp.release_app.login',$post);
		exi('生成版本成功,请下载发布！','','/setting.wxapp/version_list/id='.$app_id.'&type='.$_RQ['apptype']);
}
if($_RQ['op']=='version_list'){
	//版本列表，显示指定小程序的版本
	$app_id=intval($_RQ['id']);
	$params=array('app_id'=>$app_id,'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['page']){
		$params['page']=intval($_RQ['page']);
	}
	if($_RQ['type']=='aliapp'){
		$return=cloud_request('wxapp.aliapp_up.list',$params);
	}elseif($_RQ['type']=='baiduapp'){
		$return=cloud_request('wxapp.baiduapp_up.list',$params);
	}elseif($_RQ['type']=='ttapp'){
		$return=cloud_request('wxapp.ttapp_up.list',$params);
	}elseif($_RQ['type']=='qqapp'){
		$return=cloud_request('wxapp.qqapp_up.list',$params);
	}else{
		$return=cloud_request('wxapp.wxapp_up.list',$params);
	}	
	$return['htmls']=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'version_list','query'=>'type=wxapp&id='.$app_id,'title'=>'微信小程序版本列表'),
			array('op'=>'version_list','query'=>'type=ttapp&id='.$app_id,'title'=>'头条/抖音版本列表'),
			array('op'=>'version_list','query'=>'type=aliapp&id='.$app_id,'title'=>'支付宝版本列表'),
			array('op'=>'version_list','query'=>'type=baiduapp&id='.$app_id,'title'=>'百度小程序列表'),
			array('op'=>'version_list','query'=>'type=qqapp&id='.$app_id,'title'=>'QQ小程序列表'),
		),
		'list'=>array('tip'=>'1、下载小程序，然后用小程序发布工具，上传发布小程序即可！</br>2、<red>如果第一次打开项目，出现异常，有时候是一些工具存在问题，可以关闭工具再次打开试试，或者预览模式试试！</red></br>3、<red>【注意】:如果支付宝小程序（或其他小程序），开发工具打开是空白的，或内容不加载出来，很有可能是：1、生成本小程序包的小程序不存在了，2、支付宝工具（左上角）没有关联小程序；3、网站不支持https</red>','delall'=>false,'del_one'=>false,'edit'=>false,'pagelist'=>false,'data'=>'list','list'=>array(
			array('type'=>'string','title'=>'生成任务ID','name'=>'id'),
			array('type'=>'string','title'=>'小程序名称','name'=>'title'),
			array('type'=>'time','title'=>'版本生成时间','name'=>'createtime'),
		),'action'=>array(
			array('type'=>'open','url'=>'zipfile','title'=>'下载'),
		)),
	);
	exi($return);
}
?>